﻿@using LanDBom.Resources
@{
    ViewBag.Title = "Requisition";
}

<h2>申请单总览</h2>

@section styles{
    <style>
        input {
            width: 100%;
        }

        fieldset {
        }

            fieldset div {
                margin-bottom: 5px
            }

        #finddiv1 {
            width: 100%;
        }

        select {
            width: 100%;
        }
        #viewdiv {
            width: 100%;
            overflow-x: scroll;
            /*overflow-y: hidden;*/
            height: 70vh;
        }
        #btable {
            width: 240%;
        }
        .scrollTbody {
            display: block;
            height: 262px;
            overflow: auto;
            width: 100%;
        }
        .table{
            table-layout:auto;
        }

        .table td, .table th {
            width: 200px;
            word-break: keep-all;
            white-space: nowrap;
        }

        .table tr {
            border-left: 1px solid #EB8;
            border-bottom: 1px solid #B74;
        }

        .rz {
            width: 300px;
        }
    </style>
}

<from>
    <div id="WT_dh_mb2" style="display: none; position: absolute; border: 1px black solid; left: 25%; top: 33%; background-color: white; background-color: #f1f1f1;height:200px;width:300px">
        <div style="text-align: right; background-color: #84acde;"><span class="WT_qxbh2" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
        <div style="margin: 20px 10px; padding: 10px; background-color: #fff;">
            <div id="WJ_XZLJ"></div>
        </div>
        <div style="text-align:center"><button class="WT_qxbh2">@Resource.String126</button></div>
    </div>
    <div id="finddiv1">
        <fieldset class="boun">
            <legend class="len">@Resource.String374</legend>
            <div class="row">
                <div class="col-2">创建日期从：</div>
                <div class="col-2"><input type="date" id="qssj" /></div>
                <div class="col-2">到:</div>
                <div class="col-2"><input type="date" id="jssj" /></div>
                <div class="col-2">截止日期</div>
                <div class="col-2"><input type="date" id="jzrrq" /></div>
                <div class="col-2">申请单号</div>
                <div class="col-2"><input type="text" id="bian" /></div>
                <div class="col-2">@Resource.String375</div>
                <div class="col-2"><input type="text" id="BB_SQ_xmmc" /></div>
                <div class="col-2">@Resource.String376</div>
                <div class="col-2"><input type="text" id="BB_SQ_khmc" /></div>
                <div class="col-2">@Resource.String377</div>
                <div class="col-2"><input type="text" id="BB_SQ_gjz" /></div>
                <div class="col-2">项目状态</div>
                <div class="col-2">
                    <select id="xmlx">
                        <option value="0">请选择</option>
                        <option value="WON Opportunities">WON Opportunities</option>
                        <option value="Open Opportunities">OPEN Opportunities</option>
                        <option value="LOST Opportunities">LOST Opportunities</option>
                    </select>
                </div>
                <div class="col-4"></div>
                <div class="col-2 btn-sm  btn-warning" id="BB_WT_cx" style="text-align:center">@Resource.String374</div>&nbsp;
                <div class="col-2  btn-sm  btn-warning" id="BB_WT_scbb" style="text-align:center">@Resource.String380</div>
            </div>
        </fieldset>
    </div>
    <div id="viewdiv">
        <table class="tab table-sm table" id="btable" style="table-layout:fixed;">
            <thead class="thead-light"> 
                <tr style="text-align:center;">
                    <th scope="col" style="width:30px;"><input type="checkbox" id="dkek"/></th>
                    <th scope="col">@Resource.String381</th>
                    <th scope="col">@Resource.String382</th>
                    <th scope="col">@Resource.String383</th>
                    <th scope="col">@Resource.String384</th>
                    <th scope="col">@Resource.String385</th>
                    <th scope="col">@Resource.String437</th>
                    <th>@Resource.String59</th>
                    <th>@Resource.String389</th>
                    <th>@Resource.String71</th>
                    <th>@Resource.String70</th>
                    <th>@Resource.String391</th>
                    <th>@Resource.String392</th>
                    <th>@Resource.String281</th>
                </tr>
            </thead>
            <tbody id="BB_WT_tb" data-spy="scroll" style="height:570px;table-layout:auto">
            </tbody>
        </table>
    </div>
    @Html.ActionLink(Resource.String394, "Inspect_Contracts", new { Controller = "Contracts", Action = "Inspect_Contracts" }, new { @class = "btn" })
</from>

@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {
            $("#li22").css({ "color": "black", "background-color": "white" })
            get_contracts()
            Generate_report()

            $(document).on("click", "#dkek", function (e) {
                if ($("#dkek").prop("checked") == true) {
                    console.log(1)
                    $(".enidh").prop("checked", true)
                }
                else {
                    $(".enidh").prop("checked", false)
                }
            })

            $(document).on("click", "#BB_WT_cx", function () {
                get_contracts()
            })
            $(document).on("click", "#app_bu1", function (e) {
                var index = $(e.targrt).parent().parent().children().eq(1).text()
                window.location.href = "/Application/Application?id=" + id;
            })
            //搜索申请单信息
            function get_contracts() {
                var BB_SQ_xmmc = $("#BB_SQ_xmmc").val()
                var BB_SQ_khmc = $("#BB_SQ_khmc").val()
                var BB_SQ_sqrq = $("#BB_SQ_sqrq").val()
                var BB_SQ_gjz = $("#BB_SQ_gjz").val()
                var qssj = $("#qsssj").val()
                var jssj = $("#jssj").val()
                var bian = $("#bian").val()
                var xmlx = $("#xmlx").val()
                var jzrq = $("#jzrrq").val()
                $.ajax({
                    url: '/Application/Requisition',
                    type: 'GET',
                    data: { "BB_SQ_xmmc": BB_SQ_xmmc, "BB_SQ_khmc": BB_SQ_khmc, "BB_SQ_gjz": BB_SQ_gjz, "state": 1, "qssj": qssj, "jssj": jssj, "danhao": bian, "xmlx": xmlx ,"jzrq":jzrq},
                    success: function (wt) {
                        newWT(wt)
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            }
            function newWT(wt) {
                $('#BB_WT_tb tr').remove();
                $.each(wt, function (i, item) {
                    var $zc = $(`
                    <tr>
                        <td  style="width:30px;"><input type="checkbox" style="width:20px;" class="enidh"/></td>
                        <td style="display:none">${item.App_id}</td>
                        <td  id="WT_SJ_S1">${item.AP_bian}</td>
                        <td  id="WT_SJ_S2">${item.App_Kehu}</td>
                        <td  id="WT_SJ_S3">${item.APP_name}</td>
                        <td  id="WT_SJ_S4">${item.App_qishi}</td>
                        <td  id="WT_SJ_S5">${item.App_JTime}</td>
                        <td  id="WT_SJ_S6">${item.App_dizhi}</td>
                        <td  id="WT_SJ_S7">${item.APP_Zhong}</td>
                        <td  id="WT_SJ_S8">${item.App_mu}</td>
                        <td  id="WT_SJ_S9">${item.App_lei}</td>
                        <td  id="WT_SJ_S10">${item.App_sho}</td>
                        <td  id="WT_SJ_S11">${item.APP_she}</td>
                        <td  id="WT_SJ_S12">${item.App_BanB}</td>
                        <td  id="WT_SJ_S12">${item.App_zhuang}</td>
                    </tr>
                `);
                $('#BB_WT_tb').append($zc);
                })
            }
            //下载excel
            function Generate_report() {
                $(document).on("click", "#BB_WT_scbb", function () {
                    var CG_XX = [];
                    var WT_RZ = [];
                    var check = $("input[class=enidh]:checked").parent().parent().length;
                    if (check <= 0) {
                        alert("至少选中一行！");
                    }
                    else {
                        $("input[class=enidh]:checked").parent().parent().each(function (index, obj) {
                            CG_XX.push({
                                AP_bian: $("td[id='WT_SJ_S1']",obj).text()
                            })
                            console.log("共" + CG_XX.length + "数据");
                            console.log(CG_XX);
                        })
                        var Employee_path = $("#Login_path").text()
                        console.log(Employee_path)

                        var userInput = prompt("请输入文件名：", "");
                        if (userInput != null) {
                            $.ajax({
                                url: "/Application/DownloadExcel",
                                type: 'POST',
                                data: { "Designdraws": CG_XX, "WT_CD": CG_XX.length, "state": 1, "excelName": userInput, "Employee_path": Employee_path },
                                success: function (text) {
                                    $("#WT_dh_mb2").css({ "display": "block" })
                                    $("#WJ_XZLJ").append($(`<a href="/Contracts/Download_file?path=${text}" id="log_SZ" class="WT_qxbh2">下载</a>`))
                                },
                                error: function (text) {
                                    alert("系统错误");
                                }
                            })
                        }
                    }
                })
            }
            $(document).on("click", ".WT_qxbh2", function () {
                $("#WT_dh_mb2").css({ "display": "none" })
                $("#WJ_XZLJ a").remove()
            })
        })
    </script>
}